
import java.util.Vector;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author namthanh
 */
public class NPC extends Sprite {
    public boolean isMove;
    public boolean key2, key8;
    public boolean key4, key6;
    public boolean setFrSeqForKey2, setFrSeqForKey8, setFrSeqForKey4, setFrSeqForKey6;
    public boolean setdieSeq, setaction;
    public int type;
    public int startR;
    public int startC;
    public int timeStop;
    public int[]seqFor2, seqFor4, seqFor6, seqFor8, stopSeq;
    public int [] dieSeq, dieSeq1, dieSeq2, stopSeq1, action1, action2;
    public boolean nextFrame;
    public boolean isdie;
    public int waitForDie;
    public static  Vector listNPC = new Vector(50);
    public NPC(Image img, int frameWith, int frameHeight, int type){
        super(img, frameWith, frameHeight);
        this.type = type;
        listNPC.addElement(this);
        isdie = false;
        if(type == 1){
            //Police          
            seqFor8 = new int[]{8, 9, 10, 11, 12, 13, 14, 15};
            seqFor6 = new int[]{16, 17, 18, 19, 20, 21, 22, 23};
            setFrame(32);
            isMove = true;
        }
        if(type == 2){
            //ong gia xem dong ho
            stopSeq = new int[]{0, 0, 0, 0, 0,  1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0,  3, 3, 3, 3};
            setFrameSequence(stopSeq);
            setFrame(0);
            isMove = true;
        }
        if(type == 3){
            // Hut thuoc
            seqFor6 = new int[]{4, 5, 5, 6, 7, 7};
            seqFor4 = new int[]{0, 1, 1, 2, 3, 3};
            stopSeq = new int[]{8, 8, 8, 9, 10, 11, 12, 12, 12, 13, 13, 13};
            action1 = new int[]{14, 15};
            dieSeq1 = new int[]{16, 17, 18};
            setFrameSequence(seqFor6);
            key6 = true;
            setFrame(0);
            isMove = true;
        }
        if(type == 4){
            // Doi mu
            seqFor2 = new int[]{0, 1, 2, 3};
            seqFor8 = new int[]{4, 5, 6, 7};
            stopSeq = new int[]{8, 8, 9, 9, 10, 10, 11, 12};
            action1 = new int[]{13, 14};
            dieSeq1 = new int[]{15, 16, 17};
            key2 = true;
            setFrameSequence(seqFor2);
            setFrame(0);
            isMove = true;
        }
        if(type == 5){
            //gai nhay
            stopSeq = new int[]{0, 1, 2, 3, 4, 5, 6, 7};
            dieSeq1 = new int[]{8, 9, 10};
            dieSeq2 = new int[]{11, 12};
            setFrameSequence(stopSeq);
            setFrame(0);
            isMove = true;
        }
        if(type == 6){
            // gang 1
            stopSeq = new int[]{0, 1, 2};
            action1 = new int[]{3, 4};
            stopSeq1 = new int[]{5};
            action2 = new int[]{7, 8};
            dieSeq1 = new int[]{9, 10, 11};
            setFrame(0);
            isMove = true;
        }
        if(type == 7){
            //bao ve
            action1 = new int[]{0, 1, 2, 3, 4};
            action2 = new int[]{8, 9, 10, 11, 12};
            dieSeq1 = new int[]{5, 6, 7};
            dieSeq2 = new int[]{6, 7};
            setFrameSequence(new int[]{0});
            isMove = true;
        }
        if(type == 8){
            //casi
            stopSeq = new int[]{0, 1, 2, 3};
            setFrameSequence(stopSeq);
            setFrame(0);
            dieSeq1 = new int[]{4, 5, 6};
            isMove = true;
        }
        if(type == 9){
            //dj
            stopSeq = new int[]{1, 2};
            setFrameSequence(stopSeq);
            setFrame(0);
            action1 = new int[]{5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 3, 4};
            dieSeq1 = new int[]{5};
            isMove = true;
        }
        if(type == 10){
            //con tin
            stopSeq = new int[]{0, 1, 2};
            dieSeq1 = new int[]{3, 4, 5};
            stopSeq1 = new int[]{6};
            dieSeq2 = new int[]{7, 8, 9, 10, 11};
            setFrameSequence(stopSeq);
            setFrame(0);
            isMove = true;
        }
        if(type == 11){
            //guitar
            stopSeq = new int[]{0, 1};
            setFrameSequence(stopSeq);
            setFrame(0);
            action1 = new int[]{3, 4};
            dieSeq1 = new int[]{5, 6, 7};
            isMove = true;
        }
        if(type == 12){
            //dan em
            seqFor2 = new int[]{11, 12, 13, 14};
            seqFor8 = new int[]{0, 1, 2, 3, 4};
            seqFor6 = new int[]{5, 6, 7};
            seqFor4 = new int[]{8, 9, 10};
            isMove = true;
        }
        if(type == 13){
            // boss
            stopSeq = new int[]{2, 3, 4, 5};
            seqFor2 = new int[]{17, 18, 19, 20};
            seqFor8 = new int[]{6, 7, 8, 9, 10};
            seqFor6 = new int[]{11, 12, 13};
            seqFor4 = new int[]{14, 15, 16};
            setFrameSequence(stopSeq);
            isMove = false;
        }
    }
    /* Reset lai trang thai mac dinh cua npc
     Tham so type la loai npc can reset
     */
    public void setDefaultStage(int type){
        if(type == 3){
            stopMove();
            setFrameSequence(seqFor6);
            key6 = true;
            setFrame(0);
            isMove = true;
            isdie = false;
        }
        if(type == 4){
            stopMove();
            key2 = true;
            setFrameSequence(seqFor2);
            setFrame(0);
            isMove = true;
            isdie = false;
        }
    }
    public void stopMove(){
        isMove = false;
        key2 = false;
        key8 = false;
        key4 = false;
        key6 = false;
    }
    public static NPC elementAt(int index){
        return (NPC)listNPC.elementAt(index);      
    }

}
